package com.ilxqx.framework.system.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.ilxqx.framework.system.enumeration.EntityEnum;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * 用户状态字段序列化
 * @author venus
 */
@JsonComponent
public class EntityEnumSerializer extends JsonSerializer<EntityEnum> {

	/**
	 * Method that can be called to ask implementation to serialize
	 * values of type this serializer handles.
	 *
	 * @param value       Value to serialize; can <b>not</b> be null.
	 * @param gen         Generator used to output resulting Json content
	 * @param serializers Provider that can be used to get serializers for
	 */
	@Override
	public void serialize(EntityEnum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
		gen.writeStartObject();
		gen.writeFieldName("value");
		gen.writeString(value.getValue());
		gen.writeFieldName("meaning");
		gen.writeString(value.getMeaning());
		gen.writeEndObject();
	}

}
